package com.itheima.admin.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.admin.dto.ChannelPageRequestDto;
import com.itheima.admin.dto.SensitivePageRequestDto;
import com.itheima.admin.mapper.AdSensitiveMapper;
import com.itheima.admin.pojo.AdSensitive;
import com.itheima.admin.service.AdSensitiveService;
import com.itheima.common.vo.PageResultVo;
import org.springframework.stereotype.Service;
import java.time.LocalDateTime;


/**
 * 分页查询
 * @param dto
 * @return
 */
@Service
public class AdSensitiveServiceImpl extends ServiceImpl<AdSensitiveMapper, AdSensitive> implements AdSensitiveService {
    @Override
    public PageResultVo findPage(SensitivePageRequestDto dto) {
        //1. 设置分布参数
        Page<AdSensitive> pageInfo = new Page<>(dto.getPage(), dto.getSize());
        //2. 设置查询条件
        LambdaQueryWrapper<AdSensitive> wrapper = new LambdaQueryWrapper<>();
        wrapper.like(dto.getSensitive()!=null, AdSensitive::getSensitives, dto.getSensitive());
        //3. 查询
        IPage<AdSensitive>pageResult =page(pageInfo,wrapper);
        System.out.println("pageResult==pageInfo? ==> " + (pageInfo==pageResult));
        //4. 构建分页结果返回
        return PageResultVo.pageResult(dto.getPage(),dto.getSize(),pageResult.getTotal(),pageResult.getRecords());
    }
    /**
     * 新增频道
     * @param adSensitive
     */
    @Override
    public void add(AdSensitive adSensitive) {
        adSensitive.setCreatedTime(LocalDateTime.now());
        save(adSensitive);
    }
}
